package com.peaksport.pkms.learn.day21.edgeservice;

import javax.ws.rs.core.Response.Status;

import org.apache.servicecomb.core.Handler;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.util.StringUtils;


public class Day21AuthenticationHandler implements Handler{

	public void handle(Invocation invocation, AsyncResponse response) throws Exception {
		//String user1 = (String) invocation.getRequestEx().getHeader("user1");
		String userName = invocation.getContext("userName");
		String pwd = invocation.getContext("pwd");
		if (StringUtils.isEmpty(userName) && !StringUtils.isEmpty(pwd)) {
			response.consumerFail(new InvocationException(Status.UNAUTHORIZED, "Handler方式--账号密码不能为空."));
			return;
		}
		invocation.next(response);
	}

}
